package com.yuelife.service.controller;

import com.github.pagehelper.PageInfo;
import com.yuelife.service.pojo.SAddress;
import com.yuelife.service.service.SAddressService;
import entity.Result;
import entity.StatusCode;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/****
 * @Author:admin
 * @Description:
 * @Date 2019/6/14 0:18
 *****/
@Api(value = "SAddressController")
@RestController
@RequestMapping("/sAddress")
@CrossOrigin
public class SAddressController {

    @Autowired
    private SAddressService sAddressService;

    /***
     * SAddress分页条件搜索实现
     * @param sAddress
     * @param page
     * @param size
     * @return
     */
    @ApiOperation(value = "SAddress条件分页查询",notes = "分页条件查询SAddress方法详情",tags = {"SAddressController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false) @ApiParam(name = "SAddress对象",value = "传入JSON数据",required = false) SAddress sAddress, @PathVariable  int page, @PathVariable  int size){
        //调用SAddressService实现分页条件查询SAddress
        PageInfo<SAddress> pageInfo = sAddressService.findPage(sAddress, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * SAddress分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @ApiOperation(value = "SAddress分页查询",notes = "分页查询SAddress方法详情",tags = {"SAddressController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用SAddressService实现分页查询SAddress
        PageInfo<SAddress> pageInfo = sAddressService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param sAddress
     * @return
     */
    @ApiOperation(value = "SAddress条件查询",notes = "条件查询SAddress方法详情",tags = {"SAddressController"})
    @PostMapping(value = "/search" )
    public Result<List<SAddress>> findList(@RequestBody(required = false) @ApiParam(name = "SAddress对象",value = "传入JSON数据",required = false) SAddress sAddress){
        //调用SAddressService实现条件查询SAddress
        List<SAddress> list = sAddressService.findList(sAddress);
        return new Result<List<SAddress>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @ApiOperation(value = "SAddress根据ID删除",notes = "根据ID删除SAddress方法详情",tags = {"SAddressController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Integer id){
        //调用SAddressService实现根据主键删除
        sAddressService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改SAddress数据
     * @param sAddress
     * @param id
     * @return
     */
    @ApiOperation(value = "SAddress根据ID修改",notes = "根据ID修改SAddress方法详情",tags = {"SAddressController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @PutMapping(value="/{id}")
    public Result update(@RequestBody @ApiParam(name = "SAddress对象",value = "传入JSON数据",required = false) SAddress sAddress,@PathVariable Integer id){
        //设置主键值
        sAddress.setAddressid(id);
        //调用SAddressService实现修改SAddress
        sAddressService.update(sAddress);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增SAddress数据
     * @param sAddress
     * @return
     */
    @ApiOperation(value = "SAddress添加",notes = "添加SAddress方法详情",tags = {"SAddressController"})
    @PostMapping
    public Result add(@RequestBody  @ApiParam(name = "SAddress对象",value = "传入JSON数据",required = true) SAddress sAddress){
        //调用SAddressService实现添加SAddress
        sAddressService.add(sAddress);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询SAddress数据
     * @param id
     * @return
     */
    @ApiOperation(value = "SAddress根据ID查询",notes = "根据ID查询SAddress方法详情",tags = {"SAddressController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @GetMapping("/{id}")
    public Result<SAddress> findById(@PathVariable Integer id){
        //调用SAddressService实现根据主键查询SAddress
        SAddress sAddress = sAddressService.findById(id);
        return new Result<SAddress>(true,StatusCode.OK,"查询成功",sAddress);
    }

    /***
     * 查询SAddress全部数据
     * @return
     */
    @ApiOperation(value = "查询所有SAddress",notes = "查询所SAddress有方法详情",tags = {"SAddressController"})
    @GetMapping
    public Result<List<SAddress>> findAll(){
        //调用SAddressService实现查询所有SAddress
        List<SAddress> list = sAddressService.findAll();
        return new Result<List<SAddress>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
